/*子应用*/
const express = require('express');

const query = require('../../pool');

const manager = express.Router();

// 加载时提供的数据
manager.get('/',async(req,res)=>{
 let result = await query('select typeid,description from taste_type')
  res.send({code:1,msg:'success',data:result})
})

// 查询返回数据
manager.get('/findpro?:params',async(req,res)=>{
  let obj = req.query;
//console.log(obj)
  let names = obj.p_name !=''?`and cakename like '${obj.p_name}%'`:'';  
  let family = obj.family != ''?`and family like '${obj.family}%'`:'';  
  let tastes = obj.tastes!=''?`and taste_type = '${obj.tastes}'`:'';  
  let params = names+family+tastes;
//console.log('参数',params)
  let sql = `select cakename,c.family,cake_label,t.description,dt.type_description,sold_count,cake_price,cake_description from cakelist c
  left join taste_type t on t.typeid = c.taste_type
  left join discount_type dt on dt.tid = c.discount_type where 1=1 and is_onsale=1 ${params} `;
  let result =await query(sql);
  // console.log(result)
  res.send({code:1,mgs:'success',data:result})
})


//暴露
module.exports = manager;